import { defHttp } from '/@/utils/http/axios';
import {
 OpmsFixResidentListGetResultModel,
 OpmsFixResidentModel,
 OpmsFixResidentPageListGetResultModel,
 OpmsFixResidentParams,
 OpmsFixResidentPageSearchParams,
 OpmsFixResidentListSearchParams,
 UpdateOpmsFixResidentParams,
 OpmsFixResidentIDType,
} from '/@/api/resident/model/OpmsFixResidentModel';

import { UploadFileParams } from '/#/axios';
import { useGlobSetting } from '/@/hooks/setting';
import { UploadApiResult } from '../sys/model/uploadModel';

// 常住居民表接口
export enum Api {
    PublicApi = '/resident/opms-fix-resident',
    ListApi = `/resident/opms-fix-resident/list`,
    PageApi = `/resident/opms-fix-resident/page`,
    BatchApi = `/resident/opms-fix-resident/batch`,
    ExportApi = `/resident/opms-fix-resident/export`,
    ImportApi = `/resident/opms-fix-resident/import`,
}
/**
 * @description:  获取列表
 * @param params
 * @returns
 */
export const getOpmsFixResidentList = (params?: OpmsFixResidentListSearchParams) =>
   defHttp.get<OpmsFixResidentListGetResultModel>({ url: Api.ListApi, params });

/**
 * @description:  分页获取列表
 * @param params
 * @returns
 */
export const getOpmsFixResidentPage = (params: OpmsFixResidentPageSearchParams) =>
  defHttp.get<OpmsFixResidentPageListGetResultModel>({ url: Api.PageApi, params });

/**
 * @description:  根据id获取
 * @param id
 * @returns
 */
export const getOpmsFixResident = (id: OpmsFixResidentIDType) =>
  defHttp.get<OpmsFixResidentModel>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  创建
 * @param params
 * @returns
 */
export const createOpmsFixResident = (params: OpmsFixResidentParams) =>
  defHttp.post<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  更新
 * @param params
 * @returns
 */
export const updateOpmsFixResident = (params: UpdateOpmsFixResidentParams) =>
  defHttp.put<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  物理删除
 * @param id
 * @returns
 */
export const deleteOpmsFixResident = (id: OpmsFixResidentIDType) =>
  defHttp.delete<boolean>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  物理批量删除
 * @param ids
 * @returns
 */
export const deleteOpmsFixResidentBatch = (ids: OpmsFixResidentIDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
 * @description:  逻辑删除
 * @param ids
 * @returns
 */
export const logicDeleteOpmsFixResident = (id: OpmsFixResidentIDType) =>
  defHttp.delete<boolean>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  逻辑批量删除
 * @param ids
 * @returns
 */
export const logicDeleteOpmsFixResidentBatch = (ids: OpmsFixResidentIDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
* @description:  导出文件
* @param ids
* @returns
*/
export const exportOpmsFixResidentListFile = (ids: OpmsFixResidentIDType[]) =>
defHttp.post<boolean>({ url: Api.ExportApi, params: { ids } });

/**
* @description:  导入文件
* @param ids
* @returns
*/
export const importOpmsFixResidentListFile = (
params: UploadFileParams,
onUploadProgress?: (progressEvent: ProgressEvent) => void,
) =>
defHttp.uploadFile<UploadApiResult>(
{
  url: useGlobSetting().apiUrl + Api.ImportApi,
  onUploadProgress,
}, params);
